<?php

namespace Controller\Company;

class Detail extends \Controller\Base {

    public function actionIndex() {
        $this->setMenuPath('Company', 'Detail');
        if ($this->isPost()) {
            $this->save();
        }
        $company = \Data\Company::instance()->getCompany();
        if(empty($company)) {
            $company = array(
                'Id' => '',
                'Name' => '',
                'Landline' => '',
                'Fax' => '',
                'Address' => '',
                'ConsumerHotline' => '',
                'WebsiteRecordNumber' => '',
                'Corporate' => ''
                );
        }
        $this->assign('company', $company);
        $this->display();
    }

    public function save(){
        $id = $this->postInt('id');
        $data = array(
            'Name' => $this->postParam('name'),
            'Landline' => $this->postParam('landline'),
            'Fax' => $this->postParam('fax'),
            'Address' => $this->postParam('address'),
            'ConsumerHotline' => $this->postParam('consumerHotline'),
            'WebsiteRecordNumber' => $this->postParam('websiteRecordNumber'),
            'Corporate' => $this->postParam('corporate')
        );
        if($id) {
            \Data\Company::instance()->updateCompany($id, $data);
        } else {
            \Data\Company::instance()->add($data);
        }
        $this->addSuccessMsg('保存成功!');
    }
}
